/*
* @description 请求
*/

import { $u } from '@/uview-ui/index.js'
import { tansParams } from "@/utils/ruoyi"

const request = function (options) {
	if ((options.method === 'get' || options.method === 'put') && options.params) {
		let url = options.url + '?' + tansParams(options.params);
		url = url.slice(0, -1);
		options.params = {};
		options.url = url;
	} else {
		options.data = options.data || options.params
		pureParams(options.data)
	}
  return $u.http.request(options)
}

// 参数处理
function pureParams (data) {
	if (Object.prototype.toString.call(data) === '[object Object]') {
		for (let key in data) {
			let value = data[key]
			if (value === null || value === undefined) {
				delete data[key]
			}
			if (value && Object.prototype.toString.call(value) === '[object Object]') {
				pureParams(value)
			}
		}
	}
}

export default request
